package com.fanpan26.thread.print;

/**
 * @author fanpan26
 */
public class Printer {

    private volatile boolean status = true;

   public void printA() throws InterruptedException {
        synchronized (this) {
            while (status) {
                wait();
            }

            System.out.println("A");
            status = true;
            notify();
        }
    }

    public void printB() throws InterruptedException {
        synchronized (this) {
            while (!status) {
                wait();
            }

            System.out.println("B");
            status = false;
            notify();
        }
    }


    public static void main(String[] args) throws InterruptedException {
        Printer printer = new Printer();
        Thread threadA = new Thread(new RunLoopPrint(printer));
        Thread threadB  = new Thread(new RunLoopPrintB(printer));
        threadA.start();
        threadB.start();

        Thread.sleep(5000);
        System.out.println("finished");
    }


}
